//
//  XCTabBarController.m
//  彩票
//
//  Created by XC on 16/10/5.
//  Copyright © 2016年 XC. All rights reserved.
//

#import "XCTabBarController.h"
#import "XCAttentionViewController.h"
#import "XCNavigationController.h"
#import "XCHomeVC.h"
#import "XCVedioVC.h"
@interface XCTabBarController ()
@property(nonatomic,strong)NSMutableArray *items;
@end

@implementation XCTabBarController

//懒加载
-(NSMutableArray *)items
{
    if (_items==nil){
        _items=[NSMutableArray array];
        
        
    }
    return _items;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
   
    self.tabBar.translucent = NO;
    
    
    self.tabBar.tintColor = [UIColor redColor];
    //添加所有的viewController
    [self setUpAllChildController];
    
   //设置tabbar
    [self setUpTabBar];
    
}

- (void)setUpTabBar {
    //创建背景图片
//    UIImageView *imageV = [[UIImageView alloc] init];
//    imageV.image = [UIImage imageNamed:@"background_Introduce_17x17_"];
//    [imageV setContentMode:UIViewContentModeCenter];
//    imageV.frame = CGRectMake(0, -8, self.tabBar.width, self.tabBar.height);
//    //把图片添加到tabBar底部
//    [self.tabBar insertSubview:imageV atIndex:0];
//    //去掉系统tabBar的线
    [self.tabBar setShadowImage:[UIImage imageWithColor:[UIColor clearColor]]];
    [self.tabBar setBackgroundImage:[UIImage imageWithColor:[UIColor clearColor]]];
    
}





//添加所有的viewController
-(void)setUpAllChildController
{
    
    XCHomeVC *homeVC = [[XCHomeVC alloc]init];
    [self setUpOneChildControllerWithViewController:homeVC image:[UIImage imageNamed:@"home_tabbar_22x22_"] selectedImage:[UIImage imageNamed:@"home_tabbar_press_22x22_"] navTitle:@"" tabTitle:@"首页"];
    
    XCVedioVC *vedioVc = [[XCVedioVC alloc]init];
    [self setUpOneChildControllerWithViewController:vedioVc image:[UIImage imageNamed:@"video_tabbar_22x22_"] selectedImage:[UIImage imageNamed:@"video_tabbar_press_22x22_"] navTitle:@"" tabTitle:@"视频"];
    
    
    XCAttentionViewController *attention=[[XCAttentionViewController alloc] init];
    
    [self setUpOneChildControllerWithViewController:attention image:[UIImage imageNamed:@"newcare_tabbar_22x22_"] selectedImage:[UIImage imageNamed:@"newcare_tabbar_press_22x22_"] navTitle:@"我关注的" tabTitle:@"关注"];


    
   
}
#define RandomCOlOR COLOR(arc4random_uniform(255), arc4random_uniform(255), arc4random_uniform(255))
//设置一个子控制器
-(void)setUpOneChildControllerWithViewController:(UIViewController *)viewController image:(UIImage *)image selectedImage:(UIImage *)selImage navTitle:(NSString *)navTitle tabTitle:(NSString *)tabTitle
{
    //系统自带的tabbar规定图片的大小不能超过49,为此自定义tabbar
    
    UINavigationController *nav=[[XCNavigationController alloc] initWithRootViewController:
                                    viewController];
    viewController.navigationItem.title=navTitle;

    nav.tabBarItem.image=image;
    
    nav.tabBarItem.selectedImage=selImage;
    nav.tabBarItem.title=tabTitle;
    [self.items addObject:nav.tabBarItem];
    
    [self addChildViewController:nav];
}


@end


